<?php
/**
 * 21天减重测评算法
 * Created by PhpStorm.
 * User: liao
 * Date: 2016/12/12
 * Time: 16:41
 */

namespace App\Services\Result;

use App\Interf\Resultable;
use Monolog\Logger;
use ParamConfig;

use App\Models\LogHelper;

class OilResult extends BaseResult implements Resultable
{
    private $answers;
    private $ResultAttrObj;

    public function __construct($answersStr = null)
    {
        $this->answers = $this->convertAnswer($answersStr);
        $this->ResultAttrObj = $this->configAttrObj(1,'测评结论');
    }

    public function result()
    {
        $attrs = [];
        array_push($attrs,$this->getOil());
        $data['attrs'] = $attrs;
        $data['chatparam'] =null;
        //图类型常规图
        $data['chatType'] = null;
        return $data;
    }



    public  function getOil()
    {
        $note = '';
        //第一部分图表
        $note .= ParamConfig::getValue('Oil.testing.pic');
        //第二部分推荐
        $answers= $this->answers;
        $firstOilName =  $answers[5]['weight'];
        $secondOilName =  $answers[6]['weight'];
        $note .=$this->secondRes($firstOilName,$secondOilName);
        $note .=ParamConfig::getValue("Oil.testing.$firstOilName.suitable");
        $note .=ParamConfig::getValue("Oil.testing.$secondOilName.suitable");
        //第三部分
        $note .=ParamConfig::getValue("Oil.testing.final");
        $obj = $this->ResultAttrObj;
        $obj = $this->compactAttrObj($obj['attr_id'],$obj['title'],$note,'');
        LogHelper::log("oil_testing=======>");
        LogHelper::log($obj);
        return $obj;
    }

    /**替换present
     * @param $firstOilName
     * @param $secondOilName
     * @return mixed
     */
    protected function secondRes($firstOilName,$secondOilName){
        $firstoil=ParamConfig::getValue("Oil.testing.$firstOilName.name");
        $secondOil=ParamConfig::getValue("Oil.testing.$secondOilName.name");
        //结论呈现部分
        $present=ParamConfig::getValue("Oil.testing.present");
        $present=str_replace('$a',$firstoil,$present);
        $present=str_replace('$b',$secondOil,$present);
        return $present;
    }





}